﻿@model Stock
<div class="main">
    @*@Html.Action("Banner")
    @Html.Action("Scroll")*@
    <div class="strdeprocess">
        <div class="line"></div>
        <ul>
            <li>
                <i>1</i>
                <span>申请操盘资金</span>
            </li>
            <li>
                <i class="cur">2</i>
                <span>支付保证金</span>
            </li>
            <li>
                <i>3</i>
                <span>操盘申请成功</span>
            </li>
            <li>
                <i>4</i>
                <span>开始投资股票</span>
            </li>
            <li class="last">
                <i>5</i>
                <span>盈利全归您</span>
            </li>

        </ul>
    </div>
    <div class="traderbox">
        <div class="content confirm stock">
            <div class="t">选择到款方式</div>
            <div style="width: auto; height: auto;overflow: hidden" id="PayType">
                <div class="c cur">
                    <p>
                        支付投资本金 @(Model.Principal)元 + 首月利息 @(Model.MatchEndowment * Model.LoanMoon / 100)元
                    </p>
                </div>
                <div class="c" style="margin-left: 30px;" mark="Intention">
                    <p>
                        先付意向金 @MathProject.GetIntention(Model.Principal)元 如违约不配资意向金不退还
                        配资成功后，支付投资本金 @(Model.Principal - MathProject.GetIntention(Model.Principal))元 + 首月利息@(Model.MatchEndowment * Model.LoanMoon / 100)元
                    </p>
                </div>
            </div>
            @if (ViewBag.BalanceAmount != null)
            {
                decimal a = Model.Principal + (Model.MatchEndowment * Model.LoanMoon / 100) - ViewBag.BalanceAmount;
                <div class="ac" id="BalanceAmount">
                    @if (a <= 0)
                    {
                        <span>您的账户余额：@(ViewBag.BalanceAmount)元</span>
                    }
                    else
                    {
                        <span>您的账户余额只剩@(ViewBag.BalanceAmount)元，本次支付还差@(a)元，<a class="blue" target="_blank" href='@Url.DomainRouteUrl(AreasConfig.Web, new { controller = "pay", action = "index", id = (ViewBag.CurentUser!=null?ViewBag.CurentUser.UserId:0) })'>马上充值</a></span>
                    }
                </div>
            }
            else
            {
                <div class="ac" id="BalanceAmount"></div>
            }
            <p>
                <input type="button" id="DetermineBtn" class="button red" value="确定操盘" />
                <input type="button" id="BackUpdate" class="button grey" value="返回修改" style="margin-left: 10px;" />
            </p>
            <div class="left">
                <div class="firminput c1">
                    <p class="i">
                        <em>@Model.Principal.MoneyFormat()</em>元
                    </p>
                    <p>投资本金</p>
                </div>
                <div class="peizi">配资</div>
                <div class="firminput c2">
                    <p class="i">
                        <em>@Model.MatchEndowment.MoneyFormat()</em>元
                    </p>
                    <p>配资金额</p>
                </div>
            </div>
            <div class="right">
                <ul>
                    <li>
                        <b>操盘须知</b>
                        <span>投资沪深A股，<q id="noneLimit">仓位不限制</q><q id="limit" style="display: none">仓位有限制</q>，盈利全归您<br /><q id="limitinfo" style="color: #cd1818"></q></span>
                    </li>
                    <li>
                        <b>总操盘资金</b>
                        <span><em id="TotalTrade2">@Model.TotalTrade.MoneyFormat()</em>元</span>
                    </li>
                    <li>
                        <b>亏损警戒线</b>
                        <span><em id="LossWarLine2">@Model.LossWarLine.MoneyFormat()</em>元</span>
                    </li>
                    <li>
                        <b>亏损平仓线</b>
                        <span><em id="LossOpenLine2" style="color: #cd1818">@Model.LossOpenLine.MoneyFormat()</em>元</span>
                    </li>
                    <li>
                        <b>资金使用期限</b>
                        <span><i>@Model.FundTime</i>个月</span>
                    </li>
                    <li>
                        <b>借款月利率</b>
                        <span><i id="ManageMoney2">@Model.LoanMoon</i>分 / 每月<i class="red">借款多、期限长、越优惠</i></span>

                    </li>
                    <li>
                        <b>开始交易时间</b>
                        <span>@(Model.StartTime == 0 ? "今天" : "下个交易日")</span>
                    </li>
                </ul>
            </div>

        </div>
    </div>
    @{Html.RenderPartial("Info");}
</div>
<script type="text/javascript">
    $(function() {
        var $PayType = $("#PayType").find("div.c");
        $PayType.bind("click", function() {
            var $this = $(this);
            $PayType.removeClass("cur");
            $this.addClass("cur");
            var mark = $this.attr("mark");
            if ($.isLogin()) {
                var a = 0;
                if (mark == "Intention") {
                    a = @(Model.Principal + (Model.MatchEndowment*Model.LoanMoon/100) - (ViewBag.BalanceAmount ?? 0));
                } else {
                    a = @(MathProject.GetIntention(Model.Principal) - (ViewBag.BalanceAmount ?? 0));
                }
                if (a <= 0) {
                    $("#BalanceAmount").html("<span>您的账户余额：" + @ViewBag.BalanceAmount + "元</span>");
                } else {
                    $("#BalanceAmount").html("<span>您的账户余额只剩" + @ViewBag.BalanceAmount + "元，本次支付还差" +a+ "元，<a href='@Url.DomainRouteUrl(AreasConfig.Web, new { controller = "pay", action = "index", id = (ViewBag.CurentUser!=null?ViewBag.CurentUser.UserId:0) })'>马上充值</a></span>");

                }
            }
        });

        $("#BackUpdate").bind("click", function() {
            window.location.href = "@Url.DomainRouteUrl(AreasConfig.Web, new { controller = "stock", action = "index", param = string.Format("Principal={0}&MatchEndowment={1}&TotalTrade={2}&LossWarLine={3}&LossOpenLine={4}&FundTime={5}&LoanMoon={6}&StartTime={7}", Model.Principal, Model.MatchEndowment, Model.TotalTrade, Model.LossWarLine, Model.LossOpenLine, Model.FundTime, Model.LoanMoon, Model.StartTime) })";
        });
        var postProject = function() {
            $.jajax({
                url: "@Url.DomainRouteUrl(AreasConfig.Web, "PostConfirm", "Stock")",
                params: {
                    Principal: "@Model.Principal",
                    MatchEndowment: "@Model.MatchEndowment",
                    TotalTrade: "@Model.TotalTrade",
                    LossWarLine: "@Model.LossWarLine",
                    LossOpenLine: "@Model.LossOpenLine",
                    FundTime: "@Model.FundTime",
                    StartTime: "@Model.StartTime",
                    LoanMoon: "@Model.LoanMoon"
                },
                callback: function(ret) {
                    if (!ret) {
                        return;
                    }
                    if (ret.data == 3) { //账户余额不足
                        $.StockWindow({
                            title: "账户余额不足",
                            id: "PostProject-Window",
                            classes: "project",
                            content: '<label>您的账户余额不足，请先充值</label><label><a target="_blank" class="button recharge" href="@Url.DomainRouteUrl(AreasConfig.Web, new { controller = "pay", action = "index", id =(ViewBag.CurentUser!=null? ViewBag.CurentUser.UserId:0) })">立即充值</a><a class="button recharge un" href="javascript:$(\'#PostProject-Window\').CloseWindow()">暂不充值</a></label>'
                        });
                    }
                    if (ret.message == "ok" && ret.data > 0) {
                        window.location.href = "/stock/seccess/" + ret.data;
                    }
                }
            });
        };
        //确定操盘
        $("#DetermineBtn").bind("click", function() {
            if (!$.isLogin()) {
                login.load(function() {
                    postProject();
                });
            } else {
                postProject();
            }
        });
    });
</script>